/****************************************

  hcit_usb_config.h
  Configuration for USB firmware
  This file defines the number of descriptors for the device.
  It must be modified by the user to match the required configuration.

  SOURCE CONTROL: $Id: hcit_usb_config.h,v 1.6 2008/11/08 07:30:06 tianwq Exp $

****************************************/

#ifndef _USB_CONFIG_H_
#define _USB_CONFIG_H_

/* Define integer types for 8/16 bit registers */
#ifndef BYTE
typedef unsigned char BYTE;
#endif
#ifndef WORD
typedef unsigned short WORD;
#endif

#define M_EP_NODATA             -1

/* Define maximum packet size for bulk endpoints */
#define M_EP_MAXP               64

/* Define maximum packet size for intr endpoints */
#define M_EP_MAXP_INTR          16

/* Command bit fields */
#define M_CMD_DATADIR           0x80

/* Request Type Field */
#define M_CMD_TYPEMASK          0x60
#define M_CMD_STDREQ            0x00
#define M_CMD_CLASSREQ          0x20
#define M_CMD_VENDREQ           0x40
#define M_CMD_STDDEVIN          0x80
#define M_CMD_STDDEVOUT         0x00
#define M_CMD_STDIFIN           0x81
#define M_CMD_STDIFOUT          0x01
#define M_CMD_STDEPIN           0x82
#define M_CMD_STDEPOUT          0x02

/* Standard Request Codes */
#define GET_STATUS              0x00
#define CLEAR_FEATURE           0x01
#define SET_FEATURE             0x03
#define SET_ADDRESS             0x05
#define GET_DESCRIPTOR          0x06
#define SET_DESCRIPTOR          0x07
#define GET_CONFIGURATION       0x08
#define SET_CONFIGURATION       0x09
#define GET_INTERFACE           0x0A
#define SET_INTERFACE           0x0B
#define SYNCH_FRAME             0x0C

/* Standard Descriptor Types */
#define M_DST_DEVICE            0x01
#define M_DST_CONFIG            0x02
#define M_DST_STRING            0x03
#define M_DST_INTERFACE         0x04
#define M_DST_ENDPOINT          0x05
#define M_DST_DEVQUAL           0x06
#define M_DST_OTHERSPEED        0x07
#define M_DST_POWER             0x08
#define M_CMD_DESCMASK          0xFF00
#define M_CMD_DEVICE            (M_DST_DEVICE<<8)
#define M_CMD_CONFIG            (M_DST_CONFIG<<8)
#define M_CMD_STRING            (M_DST_STRING<<8)
#define M_CMD_DEVQUAL           (M_DST_DEVQUAL<<8)
#define M_CMD_OTHERSPEED        (M_DST_OTHERSPEED<<8)

/* Endpoint transfer types */
#define M_EP_TFMASK             0x03
#define M_EP_CONTROL            0x00
#define M_EP_ISO                0x01
#define M_EP_BULK               0x10
#define M_EP_INTR               0x11

/* Standard Device Feature Selectors */
#define M_FTR_DEVREMWAKE        0x0001

/* Endpoint 0 states */
typedef enum
{
    M_EP0_IDLE = 0,
    M_EP0_RX = 1,
    M_EP0_TX = 2
}USB_EP0_STATE;

/* Endpoint 0 status structure */
typedef struct M_EP0_STATUS {
    USB_EP0_STATE   nState;         /* IDLE/RX/TX */
    int   nBytesLeft;               /* Number of bytes left to send in TX mode */
    void *pData;                    /* Pointer to data to transmit/receive */
    int   nBytesRecv;               /* Number of bytes received in RX mode */
    BYTE  byFAddr;                  /* New function address */
} M_EP0_STATUS;
typedef M_EP0_STATUS * PM_EP0_STATUS;

/* Bulk In Endpoint status structure */
typedef struct M_EPBIN_STATUS {
    volatile void *pData;               /* Pointer to data to transmit */
    int   nBytesLeft;                   /* Number of bytes left to send */
    volatile void *pDataheader;         /* Pointer to data to transmit */
    int   nBytesLeftheader;             /* Number of bytes left to send */
    BYTE  byEP;                         /* Endpoint number */
    BYTE  byEP_MAXP;                    /* Endpoint number */
} M_EPBIN_STATUS;
typedef M_EPBIN_STATUS * PM_EPBIN_STATUS;

/* Bulk Out Endpoint status structure */
typedef struct M_EPBOUT_STATUS {
    volatile void *pData;           /* Pointer to data buffer */
    int   nBuffLen;                 /* Length of data buffer */
    int   nBytesLeft;               /* Number of bytes left to receive */
    volatile int   nBytesRecv;      /* Number of bytes received */
    BYTE  byEP;                     /* Endpoint number */
} M_EPBOUT_STATUS;
typedef M_EPBOUT_STATUS * PM_EPBOUT_STATUS;

/* Command structure */
typedef struct COMMAND {
    BYTE  bmRequestType;
    BYTE  bRequest;
    WORD  wValue;
    WORD  wIndex;
    WORD  wLength;
} COMMAND;
typedef COMMAND * PCOMMAND;

__packed
/* Standard Device Descriptor */
typedef struct STD_DEV_DSCR {
    BYTE  bLength;
    BYTE  bDescriptorType;
    WORD  bcdUSB;
    BYTE  bDeviceClass;
    BYTE  bDeviceSubClass;
    BYTE  bDeviceProtocol;
    BYTE  bMaxPacketSize0;
    WORD  idVendor;
    WORD  idProduct;
    WORD  bcdDevice;
    BYTE  iManufacturer;
    BYTE  iProduct;
    BYTE  iSerialNumber;
    BYTE  bNumConfigurations;
} STD_DEV_DSCR;
typedef STD_DEV_DSCR * PSTD_DEV_DSCR;

__packed
/* Standard Configuration Descriptor */
typedef struct STD_CFG_DSCR {
    BYTE  bLength;
    BYTE  bDescriptorType;
    WORD  wTotalLength;
    BYTE  bNumInterfaces;
    BYTE  bConfigurationValue;
    BYTE  iConfiguration;
    BYTE  bmAttributes;
    BYTE  bMaxPower;
} STD_CFG_DSCR;
typedef STD_CFG_DSCR * PSTD_CFG_DSCR;

__packed
/* Standard Interface Descriptor */
typedef struct STD_IF_DSCR {
    BYTE  bLength;
    BYTE  bDescriptorType;
    BYTE  bInterfaceNumber;
    BYTE  bAlternateSetting;
    BYTE  bNumEndpoints;
    BYTE  bInterfaceClass;
    BYTE  bInterfaceSubClass;
    BYTE  bInterfaceProtocol;
    BYTE  iInterface;
} STD_IF_DSCR;
typedef STD_IF_DSCR * PSTD_IF_DSCR;

__packed
/* Standard Endpoint Descriptor */
typedef struct STD_EP_DSCR {
    BYTE  bLength;
    BYTE  bDescriptorType;
    BYTE  bEndpointAddress;
    BYTE  bmAttributes;
    WORD  wMaxPacketSize;
    BYTE  bInterval;
} STD_EP_DSCR;
typedef STD_EP_DSCR * PSTD_EP_DSCR;

/* Define maximum packet size for endpoint 0 */
#define M_EP0_MAXP              64  /* HCI Commands*/

/* Define maximum number of interfaces in a configuration */
#define M_MAXIFS                16

/* Define values for Standard Device Descriptor */
#define M_DEVDSC_CLASS          0xE0    /* Device Class */          /* Wireless Controller. */
#define M_DEVDSC_SUBCLASS       0x01    /* Device SubClass */       /* RF Controller. */
#define M_DEVDSC_PROTOCOL       0x01    /* Device Protocol */       /* Bluetooth programming. */
#define M_DEVDSC_VENDOR         0x0A12  /* Vendor ID */
#define M_DEVDSC_PRODUCT        0x0001  /* Product ID */
#define M_DEVDSC_RELEASE        PRH_BS_CFG_LMP_SUBVERSION  /* Release number */
#define M_DEVDSC_MANUI          0       /* Manufacturer string index */
#define M_DEVDSC_PRODI          0x00    /* Product string index */
#define M_DEVDSC_SERIALI        0       /* Serial number string index */
#define M_DEVDSC_CONFIGS        1       /* Number of configurations */


/* Define values for descriptors in configuration 2 */
#define M_CFG2_NUMIFS           2       /* Number of interfaces */
#define M_CFG2_CFGI             0       /* Configuration description string index */
#define M_CFG2_ATTRIBUTES       0x00    /* Configuration attributes */
#define M_CFG2_MAXPOWER         0       /* Maximum power (units of 2 mA) */

/* Interface 0, alternate 0 */
#define M_CFG2_I0A0_NUMEPS      3           /* Number of endpoints */
#define M_CFG2_I0A0_IFCLASS     0xE0        /* Interface class */
#define M_CFG2_I0A0_IFSUBCLASS  0x01        /* Interface subclass */
#define M_CFG2_I0A0_IFPROTOCOL  0x01        /* Interface protocol */
#define M_CFG2_I0A0_IFI         0           /* Interface string index */
#define M_CFG2_I0A0_0_EPADDR    0x81        /* Endpoint address (endpoint 1 IN) */
#define M_CFG2_I0A0_0_ATTRIB    0x03        /* Endpoint attributes (intr) */
#define M_CFG2_I0A0_0_MAXP      0x0010      /* Endpoint max packet size (64) */
#define M_CFG2_I0A0_0_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I0A0_1_EPADDR    0x82        /* Endpoint address (endpoint 2 IN) */
#define M_CFG2_I0A0_1_ATTRIB    0x02        /* Endpoint attributes (bulk) */
#define M_CFG2_I0A0_1_MAXP      0x0040      /* Endpoint max packet size (64) */
#define M_CFG2_I0A0_1_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I0A0_2_EPADDR    0x02        /* Endpoint address (endpoint 2 OUT) */
#define M_CFG2_I0A0_2_ATTRIB    0x02        /* Endpoint attributes (bulk) */
#define M_CFG2_I0A0_2_MAXP      0x0040      /* Endpoint max packet size (64) */
#define M_CFG2_I0A0_2_INTER     0x01        /* Endpoint interval */

/* Interface 1, alternate 0 */
#define M_CFG2_I1A0_NUMEPS      2           /* Number of endpoints */
#define M_CFG2_I1A0_IFCLASS     0xE0        /* Interface class */
#define M_CFG2_I1A0_IFSUBCLASS  0x01        /* Interface subclass */
#define M_CFG2_I1A0_IFPROTOCOL  0x01        /* Interface protocol */
#define M_CFG2_I1A0_IFI         0           /* Interface string index */
#define M_CFG2_I1A0_0_EPADDR    0x83        /* Endpoint address (endpoint 2 IN) */
#define M_CFG2_I1A0_0_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A0_0_MAXP      0x0000      /* Endpoint max packet size (64) */
#define M_CFG2_I1A0_0_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I1A0_1_EPADDR    0x03        /* Endpoint address (endpoint 2 OUT) */
#define M_CFG2_I1A0_1_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A0_1_MAXP      0x0000      /* Endpoint max packet size (64) */
#define M_CFG2_I1A0_1_INTER     0x01        /* Endpoint interval */

/* Interface 1, alternate 1 */
#define M_CFG2_I1A1_NUMEPS      2           /* Number of endpoints */
#define M_CFG2_I1A1_IFCLASS     0xE0        /* Interface class */
#define M_CFG2_I1A1_IFSUBCLASS  0x01        /* Interface subclass */
#define M_CFG2_I1A1_IFPROTOCOL  0x01        /* Interface protocol */
#define M_CFG2_I1A1_IFI         0           /* Interface string index */
#define M_CFG2_I1A1_0_EPADDR    0x83        /* Endpoint address (endpoint 2 IN) */
#define M_CFG2_I1A1_0_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A1_0_MAXP      0x0009      /* Endpoint max packet size (9) */
#define M_CFG2_I1A1_0_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I1A1_1_EPADDR    0x03        /* Endpoint address (endpoint 2 OUT) */
#define M_CFG2_I1A1_1_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A1_1_MAXP      0x0009      /* Endpoint max packet size (9) */
#define M_CFG2_I1A1_1_INTER     0x01        /* Endpoint interval */

/* Interface 1, alternate 2 */
#define M_CFG2_I1A2_NUMEPS      2           /* Number of endpoints */
#define M_CFG2_I1A2_IFCLASS     0xE0        /* Interface class */
#define M_CFG2_I1A2_IFSUBCLASS  0x01        /* Interface subclass */
#define M_CFG2_I1A2_IFPROTOCOL  0x01        /* Interface protocol */
#define M_CFG2_I1A2_IFI         0           /* Interface string index */
#define M_CFG2_I1A2_0_EPADDR    0x83        /* Endpoint address (endpoint 2 IN) */
#define M_CFG2_I1A2_0_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A2_0_MAXP      0x0011      /* Endpoint max packet size (9) */
#define M_CFG2_I1A2_0_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I1A2_1_EPADDR    0x03        /* Endpoint address (endpoint 2 OUT) */
#define M_CFG2_I1A2_1_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A2_1_MAXP      0x0011      /* Endpoint max packet size (9) */
#define M_CFG2_I1A2_1_INTER     0x01        /* Endpoint interval */

/* Interface 1, alternate 3 */
#define M_CFG2_I1A3_NUMEPS      2           /* Number of endpoints */
#define M_CFG2_I1A3_IFCLASS     0xE0        /* Interface class */
#define M_CFG2_I1A3_IFSUBCLASS  0x01        /* Interface subclass */
#define M_CFG2_I1A3_IFPROTOCOL  0x01        /* Interface protocol */
#define M_CFG2_I1A3_IFI         0           /* Interface string index */
#define M_CFG2_I1A3_0_EPADDR    0x83        /* Endpoint address (endpoint 2 IN) */
#define M_CFG2_I1A3_0_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A3_0_MAXP      0x0019      /* Endpoint max packet size (25) */
#define M_CFG2_I1A3_0_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I1A3_1_EPADDR    0x03        /* Endpoint address (endpoint 2 OUT) */
#define M_CFG2_I1A3_1_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A3_1_MAXP      0x0019      /* Endpoint max packet size (25) */
#define M_CFG2_I1A3_1_INTER     0x01        /* Endpoint interval */

/* Interface 1, alternate 4 */
#define M_CFG2_I1A4_NUMEPS      2           /* Number of endpoints */
#define M_CFG2_I1A4_IFCLASS     0xE0        /* Interface class */
#define M_CFG2_I1A4_IFSUBCLASS  0x01        /* Interface subclass */
#define M_CFG2_I1A4_IFPROTOCOL  0x01        /* Interface protocol */
#define M_CFG2_I1A4_IFI         0           /* Interface string index */
#define M_CFG2_I1A4_0_EPADDR    0x83        /* Endpoint address (endpoint 2 IN) */
#define M_CFG2_I1A4_0_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A4_0_MAXP      0x0021      /* Endpoint max packet size (33) */
#define M_CFG2_I1A4_0_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I1A4_1_EPADDR    0x03        /* Endpoint address (endpoint 2 OUT) */
#define M_CFG2_I1A4_1_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A4_1_MAXP      0x0021      /* Endpoint max packet size (33) */
#define M_CFG2_I1A4_1_INTER     0x01        /* Endpoint interval */

/* Interface 1, alternate 5 */
#define M_CFG2_I1A5_NUMEPS      2           /* Number of endpoints */
#define M_CFG2_I1A5_IFCLASS     0xE0        /* Interface class */
#define M_CFG2_I1A5_IFSUBCLASS  0x01        /* Interface subclass */
#define M_CFG2_I1A5_IFPROTOCOL  0x01        /* Interface protocol */
#define M_CFG2_I1A5_IFI         0           /* Interface string index */
#define M_CFG2_I1A5_0_EPADDR    0x83        /* Endpoint address (endpoint 2 IN) */
#define M_CFG2_I1A5_0_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A5_0_MAXP      0x0031      /* Endpoint max packet size (49) */
#define M_CFG2_I1A5_0_INTER     0x01        /* Endpoint interval */
#define M_CFG2_I1A5_1_EPADDR    0x03        /* Endpoint address (endpoint 2 OUT) */
#define M_CFG2_I1A5_1_ATTRIB    0x01        /* Endpoint attributes (Isoch) */
#define M_CFG2_I1A5_1_MAXP      0x0031      /* Endpoint max packet size (49) */
#define M_CFG2_I1A5_1_INTER     0x01        /* Endpoint interval */


/*
  Define configuration structures
  The configuration structures need to be modified to match the required configuration
  Each configuration should start with a configuration descriptor
  followed by 1 or more interface descriptors (each of which is followed by
  endpoint descriptors for all the endpoints in that interface).
  The interface descriptors should start with interface 0, alternate setting 0.
  Followed by any alternate settings for interface 0.
  Then interface 1 (if more than 1 interface in the configuration), followed
  by any alternate settings for interface 1.
  This arrangement should be repeated for all interfaces in the configuration.
*/

/* Configuration 2 */
typedef struct M_CFG_2 {
    STD_CFG_DSCR  stdcfg;         /* Required Standard Configuration Descriptor */
    STD_IF_DSCR   stdif00;        /* Interface 0 Descriptor */
    STD_EP_DSCR   stdep00_0;      /* 1st Endpoint Descriptor for Interface 0 */
    STD_EP_DSCR   stdep00_1;      /* 2nd Endpoint Descriptor for Interface 0 */
    STD_EP_DSCR   stdep00_2;      /* 3nd Endpoint Descriptor for Interface 0 */
    STD_IF_DSCR   stdif10;        /* Interface 1 Alternate 0 Descriptor */
    STD_EP_DSCR   stdep10_0;      /* 1st Endpoint Descriptor for Interface 1 */
    STD_EP_DSCR   stdep10_1;      /* 2nd Endpoint Descriptor for Interface 1 */
    STD_IF_DSCR   stdif11;        /* Interface 1 Alternate 1 Descriptor */
    STD_EP_DSCR   stdep11_0;      /* 1st Endpoint Descriptor for Interface 1 */
    STD_EP_DSCR   stdep11_1;      /* 2nd Endpoint Descriptor for Interface 1 */
    STD_IF_DSCR   stdif12;        /* Interface 1 Alternate 2 Descriptor */
    STD_EP_DSCR   stdep12_0;      /* 1st Endpoint Descriptor for Interface 1 */
    STD_EP_DSCR   stdep12_1;      /* 2nd Endpoint Descriptor for Interface 1 */
    STD_IF_DSCR   stdif13;        /* Interface 1 Alternate 3 Descriptor */
    STD_EP_DSCR   stdep13_0;      /* 1st Endpoint Descriptor for Interface 1 */
    STD_EP_DSCR   stdep13_1;      /* 2nd Endpoint Descriptor for Interface 1 */
    STD_IF_DSCR   stdif14;        /* Interface 1 Alternate 4 Descriptor */
    STD_EP_DSCR   stdep14_0;      /* 1st Endpoint Descriptor for Interface 1 */
    STD_EP_DSCR   stdep14_1;      /* 2nd Endpoint Descriptor for Interface 1 */
    STD_IF_DSCR   stdif15;        /* Interface 1 Alternate 5 Descriptor */
    STD_EP_DSCR   stdep15_0;      /* 1st Endpoint Descriptor for Interface 1 */
    STD_EP_DSCR   stdep15_1;      /* 2nd Endpoint Descriptor for Interface 1 */
} M_CFG_2;
typedef M_CFG_2 * PM_CFG_2;

/* Top level structure containing pointers to each configuration */
typedef struct M_CFG {
    PM_CFG_2      pcfg2;          /* Pointer to M_CFG_1 */
} M_CFG;
typedef M_CFG * PM_CFG;

#endif /* _CONFIG_H_ */
